package com.budwk.app.sqfw.controllers.admin.customservice;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.util.ObjectUtil;
import com.budwk.app.common.config.AppException;
import com.budwk.app.sqfw.models.Sqfw_formSummary_new;
import com.budwk.app.sqfw.services.SqfwFormsummaryNewService;
import com.budwk.app.sqfw.services.common.SqfwCustomForAdminCommonService;
import com.budwk.app.sqfw.vo.SqfwCustomForAdminCommonVO;
import com.budwk.app.sqfwDoc.bo.ExcelCreateConfig;
import com.budwk.app.sqfwV2.service.dayingRoad.DaYingLuRedWhiteRecordPdfService;
import com.budwk.starter.common.openapi.annotation.*;
import com.budwk.starter.common.page.Pagination;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.common.result.ResultCode;
import com.budwk.starter.log.annotation.SLog;
import lombok.extern.slf4j.Slf4j;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;

import java.util.List;

/**
 * @program: dfxy-community
 * @description: 大营路街道红白事备案控类
 * @author: LJT
 * @create: 2024-02-06 09:45
 **/
@IocBean
@At("/platform/sqfw/DaYingLuRedWhite")
@ApiDefinition(tag = "大营路街道红白事备案（后台管理系统）")
@Slf4j
public class DaYingLuRedWhiteRecordForAdminController {

    @Inject(value = "DaYingLuRedWhiteRecordForAdminService")
    private SqfwCustomForAdminCommonService sqfwCustomForAdminCommonService;

    @Inject
    private DaYingLuRedWhiteRecordPdfService daYingLuRedWhiteRecordPdfService;

    @Inject
    private SqfwFormsummaryNewService sqfwFormsummaryNewService;

    /**
     * 列表查询
     */
    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "列表查询")
    @ApiFormParams(
            value = {
                    @ApiFormParam(name = "pageNo", example = "1", description = "页码", type = "integer"),
                    @ApiFormParam(name = "pageSize", example = "10", description = "页大小", type = "integer"),
                    @ApiFormParam(name = "pageOrderName", example = "create_date", description = "排序字段"),
                    @ApiFormParam(name = "pageOrderBy", example = "descending", description = "排序方式")
            },
            implementation = SqfwCustomForAdminCommonVO.class
    )
    @ApiResponses(
            implementation = SqfwCustomForAdminCommonVO.class
    )
    @SLog(tag = "公共列表查询（后台管理系统）", value = "${args[0]}}")
    @SaCheckLogin
    public Result<?> list(@Param("..") SqfwCustomForAdminCommonVO bean,
                          @Param("pageNo") int pageNo,
                          @Param("pageSize") int pageSize,
                          @Param("pageOrderName") String pageOrderName,
                          @Param("pageOrderBy") String pageOrderBy) {
        Pagination pagination = sqfwCustomForAdminCommonService.list(bean);
        return Result.data(pagination);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @At
    @Ok("json")
    @DELETE
    @ApiOperation(name = "删除列表信息")
    @ApiFormParams(
            {
                    @ApiFormParam(name = "id", description = "唯一标识", required = true, check = true)
            }
    )
    @SLog(tag = "删除消防信息", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> delete(@Param("id") String id) {
        sqfwCustomForAdminCommonService.delete(id);
        return Result.success();
    }

    /**
     * excel下载
     * @param sqfwFormSummaryForAdminVO
     * @return
     */
    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "Excel文件下载")
    @SLog(tag = "Excel文件下载", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> downloadExcel(@Param("excelConfigList") List<ExcelCreateConfig> excelConfigList, @Param("..") SqfwCustomForAdminCommonVO sqfwFormSummaryForAdminVO) {
        return Result.data(sqfwCustomForAdminCommonService.downloadExcel(excelConfigList, sqfwFormSummaryForAdminVO));
    }

    /**
     * pdf下载
     * @param sqfwFormSummaryForAdminVO
     * @return
     */
    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "pdf文件下载")
    @SLog(tag = "pdf文件下载", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> downloadPdf(@Param("excelConfigList") List<ExcelCreateConfig> excelConfigList, @Param("..") SqfwCustomForAdminCommonVO sqfwFormSummaryForAdminVO) {
        return Result.data(sqfwCustomForAdminCommonService.downloadPdfList(excelConfigList, sqfwFormSummaryForAdminVO));
    }

    /**
     * 重新生成pdf
     * @param id
     * @return
     */
    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "pdf文件下载")
    @SLog(tag = "pdf文件下载", value = "${args[0]}")
    //@SaCheckLogin
    public Result<?> regeneratePdf(@Param("id") String id) {
        Sqfw_formSummary_new formSummary = sqfwFormsummaryNewService.fetch(id);
        if (ObjectUtil.isEmpty(formSummary)) {
            throw new AppException(ResultCode.NULL_DATA_ERROR.getMsg());
        }
        return Result.data(daYingLuRedWhiteRecordPdfService.getPdfCreateField(formSummary));
    }

    /**
     * 获取下载文件列表及数据检查
     */
    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "获取下载文件列表及数据检查")
    @ApiResponses(
            implementation = SqfwCustomForAdminCommonVO.class
    )
    @SLog(tag = "获取下载文件列表及数据检查", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> checkDataInfoList(@Param("..") SqfwCustomForAdminCommonVO sqfwFormSummaryForAdminVO) {
        return Result.data(sqfwCustomForAdminCommonService.checkDataInfoList(sqfwFormSummaryForAdminVO));
    }
}
